package com.tjec.project.projectWorkbench.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.projectWorkbench.domain.BmsReportNo;
import com.tjec.project.projectWorkbench.service.IBmsReportNoService;
import com.tjec.project.system.domain.BmsReportType;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 报告号Controller
 * 
 * @author tjec
 * @date 2020-07-20
 */
@RestController
@RequestMapping("/projectWorkbench/reportNo")
public class BmsReportNoController extends BaseController
{
    @Autowired
    private IBmsReportNoService bmsReportNoService;

    /**
     * 查询报告号列表
     */
    //@PreAuthorize("@ss.hasPermi('system:no:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsReportNo bmsReportNo)
    {
        startPage();
        List<BmsReportNo> list = bmsReportNoService.selectBmsReportNoList(bmsReportNo);
        return getDataTable(list);
    }

    /**
     * 导出报告号列表
     */
    //@PreAuthorize("@ss.hasPermi('system:no:export')")
    @Log(title = "报告号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsReportNo bmsReportNo)
    {
        List<BmsReportNo> list = bmsReportNoService.selectBmsReportNoList(bmsReportNo);
        ExcelUtil<BmsReportNo> util = new ExcelUtil<BmsReportNo>(BmsReportNo.class);
        return util.exportExcel(list, "咨询报告号");
    }

    /**
     * 获取报告号详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:no:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsReportNoService.selectBmsReportNoByGuid(guid));
    }

    /**
     * 新增报告号
     */
    //@PreAuthorize("@ss.hasPermi('system:no:add')")
    @Log(title = "报告号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsReportNo bmsReportNo)
    {
        return AjaxResult.success(bmsReportNoService.insertBmsReportNo(bmsReportNo));
    }

    /**
     * 修改报告号
     */
    //@PreAuthorize("@ss.hasPermi('system:no:edit')")
    @Log(title = "报告号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsReportNo bmsReportNo)
    {
        return toAjax(bmsReportNoService.updateBmsReportNo(bmsReportNo));
    }

    /**
     * 删除报告号
     */
    //@PreAuthorize("@ss.hasPermi('system:no:remove')")
    @Log(title = "报告号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(bmsReportNoService.deleteBmsReportNoByGuids(guids));
    }
    
    /**
     * 检查本业务下本报告类别是否已存在报告号
     */
    //@PreAuthorize("@ss.hasPermi('system:no:list')")
    @GetMapping("/checkBmsReportNo")
    public AjaxResult checkBmsReportNo(BmsReportNo bmsReportNo)
    {
        return AjaxResult.success(bmsReportNoService.checkBmsReportNo(bmsReportNo));
    }
    
    /**
     * 成果校审获取报告类型和报告号
     */
    //@PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/getReportTypeList")
    public AjaxResult getReportTypeList(BmsReportNo bmsReportNo)
    {
        List<BmsReportNo> list = bmsReportNoService.selectReportTypeAndNoList(bmsReportNo);
        return AjaxResult.success(list);
    }
}
